package com.example.foodsy.utils;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {

    // 获取当前登录企业的ID（仅用于企业用户）
    public static Integer getCurrentCompanyId() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null && authentication.getPrincipal() instanceof Integer) {
            return (Integer) authentication.getPrincipal();
        }
        return null;
    }

    // 获取当前登录用户的角色（ADMIN/COMPANY）
    public static String getCurrentRole(String token) {
        JwtUtils jwtUtils = SpringContextUtils.getBean(JwtUtils.class);
        return jwtUtils.extractRole(token);
    }
}